home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-26 | 1.4 KB | 65 lines | [TEXT/ScoM] |
- MAKING DEF-CLASS ACCEPT VARIABLES
-
- >one question:
- >;********
- >(setq
- >sect 's1
- >instrument 'i2
- >sym (nreverse '(a b c d e f))
- >)
- >
- >(def-class symbol instrument sect sym)
- >
- >;Why I can't set the class through its variables
- >
- >(same-as symbol of i2 in s1) ;<-- I want this
- >
- >(same-as symbol of instrument in sect) ;<-- but I get this
- >;********
- >
- >Is possible to directly define the class inside a section
- >without using the macro def-class or def-section?
- >(something like make-instance or slot-value)
- >
- >I can not use def-class inside a function or macro
- >using variables for instruments and sections
-
- You must use backquote.
-
- (setq sym '(a b c))
- (setq instrument 'i2)
- (setq sect 's1)
-
- (eval `(def-class symbol ,instrument ,sect ',sym))
-
- (same-as symbol of i2 in s1)
- --> (a b c)
-
- Explanation
-
- Backquote quotes the list except those elements which are
- preceded by , which evaluates the contents. Hence when
- you evaluate this once
-
- `(def-class symbol ,instrument ,sect ',sym)
-
- it creates the following code
-
- (def-class symbol i2 s1 '(a b c))
-
- When you evaluate it second time it makes class definition.
-
- Use do-quietly to get rid of listener messages.
-
- (defun define-my-classes ()
- (let ((sym '(a b c))
- (instrument 'i2)
- (sect 's1))
- (do-quietly
- (eval `(def-class symbol ,instrument ,sect ',sym)))))
-
- (define-my-classes)
- (same-as symbol of i2 in s1)
- --> (a b c)
-
-